<?php
/**
 * User: miguelpuig
 * Date: 27/09/13
 * Time: 17:08
 * To change this template use File | Settings | File Templates.
 */

error_reporting(E_ALL);
ini_set('display_errors','On');
echo "Installing <br />";

$current_path = realpath(dirname(__FILE__));


//Installing BKM Package
$sites = array();

$sites[0] = new stdClass();
$sites[0]->lang = 'en';
$sites[0]->langst = 'en-GB';
$sites[0]->path = '/var/www/brinkman/2013/www.brinkman.com/';



$sites[1] = new stdClass();
$sites[1]->lang = 'nl';
$sites[1]->langst = 'nl-NL';
$sites[1]->path = '/var/www/brinkman/2013/www.brinkman.nl/';



$sites[2] = new stdClass();
$sites[2]->lang = 'de';
$sites[2]->langst = 'de-DE';
$sites[2]->path = '/var/www/brinkman/2013/www.brinkmanagro.de/';


$path_com_virtuemart_site  = 'components/com_virtuemart/';
$path_com_bkmcatalog_site  = 'components/com_brinkmanvm/';
$path_com_bkmcatalog_admin = 'administrator/components/com_brinkmanvm/';
$path_languages_override   = 'language/overrides';
$path_plugins_search_virtuemart = 'plugins/search/virtuemart/';
$path_template_bkm = 'templates/bkm/';


$self_com_virtuemart_site  = $current_path.'/components/com_virtuemart/site/';
$self_com_bkmcatalog_site  = $current_path.'/components/com_brinkmanvm/site/';
$self_com_bkmcatalog_admin = $current_path.'/components/com_brinkmanvm/administrator/';
$self_languages_override   = $current_path.'/languages/';
$self_plugins_search_virtuemart = $current_path.'/plugins/search/virtuemart/';
$self_template_bkm = $current_path.'/template/bkm/';



foreach ($sites as $key=>$site):

    if (file_exists($site->path)):
        echo "Installing virtue_mart Site on the ".$site->lang." site<br />";
        copy($current_path.'/components/com_virtuemart/productdetails.php',$site->path.$path_com_virtuemart_site.'controllers/productdetails.php');

        echo "Installing virtue_mart Site on the ".$site->lang." site<br />";
        copy($current_path.'/components/com_virtuemart/shopfunctionsf.php',$site->path.$path_com_virtuemart_site.'helpers/shopfunctionsf.php');


        echo "Installing com_bkmcatalog_site on the ".$site->lang." site<br />";
        recurse_copy($self_com_bkmcatalog_site,$site->path.$path_com_bkmcatalog_site);

        echo "Installing path_com_bkmcatalog_admin on the ".$site->lang." site<br />";
        recurse_copy($self_com_bkmcatalog_admin,$site->path.$path_com_bkmcatalog_admin);

        echo "Installing languages on the ".$site->lang." site<br />";
        recurse_copy($self_languages_override,$site->path.$path_languages_override);

        echo "Installing language localise on the ".$site->lang." site<br />";
        copy($current_path.'/languages/'.$site->langst.".localise.php",$site->path.'language/'.$site->langst.'/'.$site->langst.".localise.php");

        echo "Installing plugins on the ".$site->lang." site<br />";
        recurse_copy($self_plugins_search_virtuemart,$site->path.$path_plugins_search_virtuemart);

        echo "Installing template on the ".$site->lang." site<br />";
        recurse_copy($self_template_bkm,$site->path.$path_template_bkm);


        echo "<hr>";
    else:
        echo "Directory ".$site->path." doesnt exist <br />";
    endif;


endforeach;



function test()
{
    echo "test";
}






function recurse_copy($src,$dst) {

    $dir = opendir($src);
    @mkdir($dst);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            }
            else {
                copy($src . '/' . $file,$dst . '/' . $file);
            }
        }
    }
    closedir($dir);
}
?>